def parse(s):
	#先解析偶数
	#放入字典
	mdict = dict()
	#返回数字列表和字典
	rnums = []
	for item in s:
		if item not in mdict:
			mdict[item] = 1
		else:
			mdict[item] += 1

	# #需要更新的字典
	# ndict = mdict
	# #删除0
	# for i in range(mdict['Z']):
	# 	rnums.append(0)
	# 	#给字典中的ERO值减少
	# 	ndict['E'] -= 1
	# 	ndict['R'] -= 1
	# 	ndict['O'] -= 1
	# #删除字典中的Z
	# del ndict['Z']
	
	# #删除2
	# for i in range(mdict['W']):
	# 	rnums.append(2)
	# 	#给字典中的ERO值减少
	# 	ndict['T'] -= 1
	# 	ndict['O'] -= 1
	# #删除字典中的W
	# del ndict['W']
	# #删除4
	# for i in range(mdict['U']):
	# 	rnums.append(4)
	# 	#给字典中的ERO值减少
	# 	ndict['F'] -= 1
	# 	ndict['O'] -= 1
	# 	ndict['R'] -= 1
	# #删除字典中的Z
	# del ndict['U']
	# #删除6
	# for i in range(mdict['X']):
	# 	rnums.append(6)
	# 	#给字典中的ERO值减少
	# 	ndict['S'] -= 1
	# 	ndict['I'] -= 1
	# #删除字典中的W
	# del ndict['X']
	# #删除8
	# for i in range(mdict['G']):
	# 	rnums.append(8)
	# 	#给字典中的ERO值减少
	# 	ndict['E'] -= 1
	# 	ndict['I'] -= 1
	# 	ndict['H'] -= 1
	# 	ndict['T'] -= 1
	# #删除字典中的W
	# del ndict['G']

	# #再处理奇数
	# #删除5
	# for i in range(mdict['F']):
	# 	rnums.append(5)
	# 	#给字典中的ERO值减少
	# 	ndict['I'] -= 1
	# 	ndict['V'] -= 1
	# 	ndict['E'] -= 1
	# #删除字典中的F
	# del ndict['F']
	# #删除7
	# for i in range(mdict['S']):
	# 	rnums.append(7)
	# 	#给字典中的ERO值减少
	# 	ndict['N'] -= 1
	# 	ndict['V'] -= 1
	# 	ndict['E'] -= 2
	# #删除字典中的F
	# del ndict['S']
	# #删除3
	# for i in range(mdict['R']):
	# 	rnums.append(3)
	# 	#给字典中的ERO值减少
	# 	ndict['T'] -= 1
	# 	ndict['H'] -= 1
	# 	ndict['E'] -= 2
	# #删除字典中的F
	# del ndict['R']
	# #删除1
	# for i in range(mdict['O']):
	# 	rnums.append(1)
	# 	#给字典中的ERO值减少
	# 	ndict['N'] -= 1
	# 	ndict['E'] -= 1
	# #删除字典中的F
	# del ndict['O']
	# for i in range(mdict['I']):
	# 	rnums.append(9)
	# #处理结果数字列表
	# res=[]
	# for n in rnums:
	# 	if n>=0 and n<7:
	# 		res.append(n+2)
	# 	elif n == 8:
	# 		res.append(0)
	# 	else:
	# 		res.append(1)
	return int(''.join(res.sort()))

while True:
	num = int(input().strip())
	for j in range(num):
		instr = input()
		print(parse(instr))